package com.tjbklx1.thread.chap09.demo02;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class FutureData extends FutureTask<RealData> implements Data {

	public FutureData(Callable<RealData> callable) {
		super(callable);
	}

//	private RealData realData = null;
//	private boolean ready = false;
//
//	public synchronized void setContent(RealData realData) {
//		if (ready) {
//			return;
//		}
//		this.realData = realData;
//		this.ready = true;
//		notifyAll();
//	}

	@Override
	public String getContent() {
//		if (!ready) {
//			try {
//				wait();
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
//		}
//		return realData.getContent();
		
		String string = null;
		try {
			string = get().getContent();
		} catch (InterruptedException | ExecutionException e) {
			e.printStackTrace();
		}
		
		return string;
	}

}
